#include <sys/types.h>
#include "../ourhdr.h"

static void charatatime(char*);


/****
 * 通过信号解决竟态条件
 **/

int main(void)
{
    pid_t pid;
    if((pid=fork())<0)
    {
        err_sys("fork error");
    }
    else if(pid == 0)
    {
        charatatime("output from child\n");    
    }
    else
    {
        charatatime("output from parent\n");
    }
    exit(0);
}

static void charatatime(char *str)
{
    char *ptr;
    int c;
    setbuf(stdout, NULL);
    for(ptr=str;c= *str++;)
    {
        putc(c,stdout);
    }
}